﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace PSI.Models {
    /// <summary>
    /// 系统菜单项
    /// </summary>
    public class MenuItem {
        public MenuItem() {
            this.Children = new List<MenuItem>();
            this.Expanded = true;
        }

        [JsonProperty("id")]
        public string Id { get; set; }

        /// <summary>
        /// 菜单标题
        /// </summary>
        [JsonProperty("caption")]
        public string Caption { get; set; }

        /// <summary>
        /// 显示次序
        /// </summary>
        [JsonProperty("showOrder")]
        public int ShowOrder { get; set; }

        /// <summary>
        /// 功能编码
        /// </summary>
        [JsonProperty("fid")]
        public string FId { get; set; }

        [JsonProperty("fidCaption")]
        public string FIdCaption { get; set; }

        [JsonProperty("parentMenuId")]
        public string ParentId { get; set; }

        [JsonProperty("parentMenuCaption")]
        public string ParentMenuCaption { get; set; }

        [JsonProperty("children")]
        public List<MenuItem> Children { get; private set; }

        [JsonProperty("leaf")]
        public bool Leaf { get { return Children.Count == 0; } }

        [JsonProperty("expanded")]
        public bool Expanded { get; set; }

        public override string ToString() {
            return string.Format("Id = {0}, 标题 = {1}, 显示次序 = {2}, 功能编号 = {3}",
                Id, Caption, ShowOrder, FId);
        }
    }
}